﻿package fwk.utiles {	

	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.display.DisplayObjectContainer;
	import fwk.interfaces.ICommonFunctions;
	
	
	public class CommonFunc extends MovieClip
	{
		
		
		//-----------------------------------------------------------------------
		function CommonFunc()
		{
			
		}
		
		//----------------------------------------------------------
		//---- Efface tous les enfants du clip
		//----------------------------------------------------------
		public function removeAllChild(clip:Object) {			
			if(clip != null && clip is DisplayObjectContainer){
				var i:int = 0;
				var nb:Number = clip.numChildren;
				var tabToDelete:Array = new Array();

				for (i = 0; i < nb; i++)
				{
					var obj:DisplayObject = clip.getChildAt(i);
					tabToDelete.push(obj);
				}
				// delete clip
				for(i=0;i<tabToDelete.length;i++){
					clip.removeChild(tabToDelete[i]);
				}
			}
		}
		//----------------------------------------------------------
		//---- Efface tous les enfants du clip ainsi que le clip container
		//----------------------------------------------------------
		public function removeObjectContainer(clip:Object){
			if(clip != null && clip is DisplayObjectContainer){
				removeAllChild(clip);
				//trace("delete clip : " + clip);
				clip.parent.removeChild(clip);
			}
			
		}
		//----------------------------------------------------------
		//---- Etats bouton
		//----------------------------------------------------------
		public function initRollOver(clip:Object){
			clip.addEventListener(MouseEvent.ROLL_OVER, n_onRollOver);
			clip.addEventListener(MouseEvent.ROLL_OUT, n_onRollOut);
		}
		
		private function n_onRollOver(evt:MouseEvent){
			(evt.currentTarget as Object).gotoAndPlay("over");
			(evt.currentTarget as Object).gotoAndPlay("on");
		}
		//----------------------------------------------------------
		private function n_onRollOut(evt:MouseEvent){
			(evt.currentTarget as Object).gotoAndPlay("out");
			(evt.currentTarget as Object).gotoAndPlay("off");
		}

	}
}
